/*
 * @Author: gk 
 * grid 框架的全局配置
 * @Date: 2018-01-17 09:53:01 
 * @Last Modified by: gk
 * @Last Modified time: 2018-04-15 09:29:42
 */
layui.define([], function (exports) {
    "use strict";
    var config = {}
    /**全局配置 */
    config = {
        /**全局配置 */
        global: {
            /**全局页数 */
            pageSize: 20,
            /**返回结果集的json结构字段名称和类型 */
            result: { 
                statusName: "state"
                , msgName: "msg"
                , dataName: "obj"
                , errorState: "ERROR"
                , okState: "OK"
            },
            /**全局页的设置 */
            page: {
                pageName: ""
                , limitName: ""
                , pages: [10, 20, 30, 50, 100]
            },
            /**定义grid返回的结果集的格式 */
            gridResponse:{
                statusName: 'state'
                ,statusCode: 'OK' 
                ,msgName: 'msg' 
                ,countName: 'total'
                ,dataName: 'obj'
              } , 
            /**自定义的消息 */
            WM_USERDEF:{
                //刷新数据单表,主表消息
                REFRESHDATA_DATA:'REFRESHDATA(DATA)'    
                //刷新明细表数据消息
                ,REFRESHDATA_DATAMX:'REFRESHDATAMX(DATA)'    
                //树节点刷新数据消息
                ,REFRESH_TREE_DATA_DATA:'REFRESH_TREE_DATA_DATA(NODE)'
                //提交完成消息
                ,AFTER_SUBMIT:'AFTER_SUMBIT'

                //画组件的消息
                ,WM_DRAW:'WM_DRAW'
            },
            /**全局的form验证规则 */
            verify: {
                /**对比两个值相等 */
                equals: function (value, item) { //value：表单的值、item：表单的DOM对象
                    var equalsId = $(item).attr("equalsId");
                    if (_.isEmpty(equalsId)) {
                        return '未配置对比id';
                    }
                    var value2 = $("#" + equalsId).val();
                    if (!_.eq(value, value2)) {
                        var equalsMsg = $(item).attr("equalsMsg");
                        if (_.isEmpty(equalsMsg)) {
                            equalsMsg = "值不相等";
                        }
                        return equalsMsg;
                    }
                },
                /**用户名验证*/
                username: [
                    /^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){2,19}$/,
                    '用户名格式不正确!'
                ],
                /** 最小、最大长度判断 */
                length: function (value, item) { //value：表单的值、item：表单的DOM对象
                    var minLength = $(item).attr("minLength");//最小长度
                    var maxLength = $(item).attr("maxLength");//最大长度
                    if (!_.isEmpty(minLength) && !_.eq('0', minLength) && _.gt(minLength, value.length)) {
                        return "输入内容小于最小值:" + minLength;
                    }
                    if (!_.isEmpty(maxLength) && !_.eq('0', maxLength) && _.gt(value.length, maxLength)) {
                        return "输入内容大于最小值:" + maxLength;
                    }
                }
            }
        }

    };
    exports("zlConfig", config);
});